const cookie = require('cookie');

// 示例：从 HTTP 请求头中提取 Cookie 字符串


// 解析所有 Cookie



p = Object.assign
var S = function (e) {
    var t, n = [];
    if (void 0 === e)
        return "";
    t = function (e) {
        for (var t, n = e.toString(), r = [], o = 0; o < n.length; o++)
            0 <= (t = n.charCodeAt(o)) && t <= 127 ? r.push(t) : 128 <= t && t <= 2047 ? (r.push(192 | 31 & t >> 6),
                r.push(128 | 63 & t)) : (2048 <= t && t <= 55295 || 57344 <= t && t <= 65535) && (r.push(224 | 15 & t >> 12),
                    r.push(128 | 63 & t >> 6),
                    r.push(128 | 63 & t));
        for (var i = 0; i < r.length; i++)
            r[i] &= 255;
        return r
    }(e);
    for (var r = 0, o = t.length; r < o; ++r)
        n.push((5 ^ t[r]).toString(16));
    return n.join("")
}

C = function (e, t) {
    var n, r = 0, o = 0;
    if ("object" != typeof e)
        return e;
    if (!t || t.length <= 0)
        return e;
    for (var i = p({
        mix_mode: r
    }, e), a = 0, c = t.length; a < c; ++a)
        void 0 !== (n = i[t[a]]) && (r |= 1,
            o |= 1,
            i[t[a]] = S(n));
    return i.mix_mode = r,
        i.fixed_mix_mode = o,
        i
}

e = {
    "account": "+86 17620532353",
    "password": "123456",
    "account_type": 0,
    "service": "https://www.toutiao.com/?wid=1744365213685"
}
t = [
    "account",
    "password"
]


const data = C(e, t)
const body = new URLSearchParams(data).toString();






fetch("https://sso.toutiao.com/get_qrcode/?service=https%3A%2F%2Fwww.toutiao.com%2F%3Fwid%3D1744369952579&need_logo=false&ui_version=3.2.1&aid=24&account_sdk_source=sso&sdk_version=2.2.5-beta.8&language=zh&verifyFp=verify_m9cotylj_Mj5RF1Og_a61s_4iSG_AoC6_MwhvSNmc1X1a&fp=verify_m9cotylj_Mj5RF1Og_a61s_4iSG_AoC6_MwhvSNmc1X1a", {
    "headers": {
        "accept": "application/json, text/javascript",
        "accept-language": "zh-CN,zh;q=0.9",
        "content-type": "application/x-www-form-urlencoded",
        "priority": "u=1, i",
        "sec-ch-ua": "\"Microsoft Edge\";v=\"135\", \"Not-A.Brand\";v=\"8\", \"Chromium\";v=\"135\"",
        "sec-ch-ua-mobile": "?0",
        "sec-ch-ua-platform": "\"Windows\"",
        "sec-fetch-dest": "empty",
        "sec-fetch-mode": "cors",
        "sec-fetch-site": "same-site",
        "x-tt-passport-csrf-token": "",
        // "cookie": "tt_webid=7492007852061263414; ttwid=1%7CwBbdP3oN1D4vCxPw41M5MUnpTjfaLRSlD_n-LeN9reg%7C1744369842%7Cfb0b66ac16b33b72672350412613f3806e62f65b223665eeb29a1be22ea8b177; _ga_QEHZPBE5HH=GS1.1.1744369953.1.0.1744369953.0.0.0; _ga=GA1.1.972071724.1744369954",
        "Referer": "https://www.toutiao.com/",
        "Referrer-Policy": "strict-origin-when-cross-origin"
    },
    "body": null,
    "method": "GET"
}).then((response) => {
    let cookies = response.headers.get("set-cookie")
    cookies.split(",").map((item) => {
        console.log(item.split(";")[0].split("=")[0]);
        console.log(item.split(";")[0].split("=")[1]);
    })
    return response.json()
}).then((data) => {
    console.log(data);
})

return



fetch("https://sso.toutiao.com/account_login/v2/?ui_version=3.2.1&aid=24&account_sdk_source=sso&sdk_version=2.2.5-beta.8&language=zh&verifyFp=verify_m9cm0ecr_SaZ4mWSp_UuED_4jSY_BrgD_UVBJMfIVB8Yb&fp=verify_m9cm0ecr_SaZ4mWSp_UuED_4jSY_BrgD_UVBJMfIVB8Yb", {
    "headers": {
        "accept": "application/json, text/javascript",
        "accept-language": "zh-CN,zh;q=0.9,en;q=0.8",
        "cache-control": "no-cache",
        "content-type": "application/x-www-form-urlencoded",
        "pragma": "no-cache",
        "priority": "u=1, i",
        "sec-ch-ua": "\"Google Chrome\";v=\"135\", \"Not-A.Brand\";v=\"8\", \"Chromium\";v=\"135\"",
        "sec-ch-ua-mobile": "?0",
        "sec-ch-ua-platform": "\"Windows\"",
        "sec-fetch-dest": "empty",
        "sec-fetch-mode": "cors",
        "sec-fetch-site": "same-site",
        "x-tt-passport-csrf-token": "4362a144d8cd6bf4518451cb070da496"
    },
    "referrer": "https://www.toutiao.com/",
    "referrerPolicy": "strict-origin-when-cross-origin",
    "body": "mix_mode=1&account=2e3d33253432333735303637363034&password=343736313033&account_type=0&service=https%3A%2F%2Fwww.toutiao.com%2F%3Fwid%3D1744365213685&fixed_mix_mode=1",
    "method": "POST",
    "mode": "cors",
    "credentials": "include"


}).then((response) => {
    console.log(response);
    return response.json()
}).then((data) => {
    console.log(data);
}).catch((error) => {
    console.log(error.message);
})


